define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clothmaking_boiler/record/index' + location.search,
                    add_url: 'clothmaking_boiler/record/add/bid/' + Config.boiler_id,
                   // edit_url: 'clothmaking_boiler/record/edit',
                   // del_url: 'clothmaking_boiler/record/del',
                    //multi_url: 'clothmaking_boiler/record/multi',
                    //import_url: 'clothmaking_boiler/record/import',
                    table: 'clothmaking_boiler_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                queryParams: function(params) {
                    if (Config.boiler_id > 0) {
                        params.filter = JSON.stringify({ 'boiler_id': Config.boiler_id });
                        params.op = JSON.stringify({ 'boiler_id': '=' });
                    }
                    return {
                        search: params.search,
                        sort: params.sort,
                        order: params.order,
                        filter: params.filter,
                        op: params.op,
                        offset: params.offset,
                        limit: params.limit,
                    };
                },
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'raw_id', title: __('Raw_id') },
                        { field: 'quantity', title: __('Quantity'), operate: 'BETWEEN' },
                        { field: 'user_id', title: __('User_id') },
                        { field: 'boiler_id', title: __('Boiler_id') },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { 
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                // {
                                //     name: 'edit',
                                //     icon: 'fa fa-pencil',
                                //     title: __('Edit'),
                                //     extend: 'data-toggle="tooltip"',
                                //     classname: 'btn btn-xs btn-success btn-editone',
                                   
                                // },
                                {
                                    name: 'del',
                                    icon: 'fa fa-trash',
                                    title: __('Del'),
                                    extend: 'data-toggle="tooltip"',
                                    confirm: '删除或修改操作后需要对釜剩余容量进行调整',
                                    classname: 'btn btn-xs btn-danger btn-delone',
                                   
                                }
                            ],
                            formatter: Table.api.formatter.operate
                          }
                           
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});